<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid区域布局</title>
    <style>
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            padding: 2rem;
        }

        h2 {
            margin: 2rem 0 1rem;
        }

        /* 示例1：基本网格区域 */
        .basic-areas {
            display: grid;
            grid-template-areas:
                "header header header"
                "sidebar main main"
                "footer footer footer";
            grid-template-columns: 200px 1fr 1fr;
            grid-template-rows: 80px 1fr 60px;
            gap: 1rem;
            min-height: 400px;
            margin-bottom: 2rem;
        }

        .basic-areas > * {
            padding: 1rem;
            background-color: #4a90e2;
            color: white;
            border-radius: 4px;
        }

        .basic-areas .header { grid-area: header; }
        .basic-areas .sidebar { grid-area: sidebar; }
        .basic-areas .main { grid-area: main; }
        .basic-areas .footer { grid-area: footer; }

        /* 示例2：复杂布局 */
        .complex-layout {
            display: grid;
            grid-template-areas:
                "nav nav nav nav"
                "sidebar-1 content content sidebar-2"
                "sidebar-1 widget-1 widget-2 sidebar-2"
                "footer footer footer footer";
            grid-template-columns: 200px 1fr 1fr 200px;
            grid-template-rows: 60px 1fr auto 60px;
            gap: 1rem;
            min-height: 600px;
            margin-bottom: 2rem;
        }

        .complex-layout > * {
            padding: 1rem;
            background-color: #4a90e2;
            color: white;
            border-radius: 4px;
        }

        .complex-layout .nav { grid-area: nav; }
        .complex-layout .sidebar-1 { grid-area: sidebar-1; }
        .complex-layout .content { grid-area: content; }
        .complex-layout .sidebar-2 { grid-area: sidebar-2; }
        .complex-layout .widget-1 { grid-area: widget-1; }
        .complex-layout .widget-2 { grid-area: widget-2; }
        .complex-layout .footer { grid-area: footer; }

        /* 示例3：响应式布局 */
        .responsive-areas {
            display: grid;
            grid-template-areas:
                "header header"
                "nav aside"
                "main aside"
                "footer footer";
            grid-template-columns: 1fr 300px;
            grid-template-rows: auto auto 1fr auto;
            gap: 1rem;
            min-height: 500px;
            margin-bottom: 2rem;
        }

        .responsive-areas > * {
            padding: 1rem;
            background-color: #4a90e2;
            color: white;
            border-radius: 4px;
        }

        .responsive-areas .header { grid-area: header; }
        .responsive-areas .nav { grid-area: nav; }
        .responsive-areas .main { grid-area: main; }
        .responsive-areas .aside { grid-area: aside; }
        .responsive-areas .footer { grid-area: footer; }

        @media (max-width: 768px) {
            .responsive-areas {
                grid-template-areas:
                    "header"
                    "nav"
                    "main"
                    "aside"
                    "footer";
                grid-template-columns: 1fr;
            }
        }

        /* 调试网格 */
        .debug-grid {
            position: relative;
        }

        .debug-grid::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
                        linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px);
            background-size: calc(100% / 3) calc(100% / 3);
            pointer-events: none;
            z-index: 1;
        }
    </style>
</head>
<body>
    <h1>Grid区域布局示例</h1>

    <h2>1. 基本网格区域</h2>
    <div class="basic-areas debug-grid">
        <header class="header">页头</header>
        <aside class="sidebar">侧边栏</aside>
        <main class="main">主要内容</main>
        <footer class="footer">页脚</footer>
    </div>

    <h2>2. 复杂布局</h2>
    <div class="complex-layout debug-grid">
        <nav class="nav">导航栏</nav>
        <aside class="sidebar-1">左侧边栏</aside>
        <main class="content">主要内容</main>
        <aside class="sidebar-2">右侧边栏</aside>
        <div class="widget-1">小部件1</div>
        <div class="widget-2">小部件2</div>
        <footer class="footer">页脚</footer>
    </div>

    <h2>3. 响应式布局</h2>
    <div class="responsive-areas debug-grid">
        <header class="header">页头</header>
        <nav class="nav">导航</nav>
        <main class="main">主要内容</main>
        <aside class="aside">侧边栏</aside>
        <footer class="footer">页脚</footer>
    </div>

    <script>
        // 添加调试网格切换功能
        document.addEventListener('keydown', (e) => {
            if (e.key === 'g' && e.ctrlKey) {
                document.querySelectorAll('.debug-grid').forEach(grid => {
                    grid.classList.toggle('show-grid');
                });
            }
        });
    </script>
</body>
</html>
